$(function () {
    $("#page").load("../back/page.html");
})
function findAll() {
    let data={
        pageNum:$.trim($("#pageNum").val()),//页数
        pageSize:$.trim($("#pageSize").val()),//条数
    };
    let da=myAjax("/back/producats/producatsFindAll",data,"post");
    setData(da.list);
    $("#pageCount").html(da.number);
}
function setData(data) {
    let html='';
    for (let i=0;i<data.length;i++){
        html +='   <tr>\n' +//字符串拼接
            '            <td>'+data[i].id+'</td>\n' +
            '            <td>'+data[i].casetypename+'</td>\n' +
            '            <td><img src="'+data[i].imgHref+'" width="20px" height="20px"></td>\n' +
            '            <td><div class="biaos">'+data[i].content+'</div></td>\n' +
            '            <td><div class="biaos">'+data[i].contentcontent+'</div></td>\n' +
            '            <td>'+data[i].title+'</td>\n' +
            '            <td><input type="button" value="编辑" onclick="updatabyid('+data[i].id+')"> <a href="javascript:deletebyid('+data[i].id+')">删除</a></td>\n' +
            '        </tr>';
    }
    $("#productsFindAll").html(html);
}

function updatabyid(id) {
    //跳转修改页面前，将值经过id传到页面
    localStorage.setItem("productId",id);//调userupdate.js里面的let userid=localStorage.getItem("userId");
    $('#reght').load('../back/products/productUpdate.html')
}

function deletebyid(id) {
    let data=myAjax("/back/producats/deleteById",{id: id},"post");
    if (data.count==1){
        alert("删除成功");
        findAll();
    } else {
        alert("删除失败");
    }
}
function findAllTh() {
    let da={
        title:$.trim($("#title").val()),
        content:$.trim($("#content").val()),
        name:$.trim($("#name").val()),
    };
    let data=myAjax("/back/producats/producatsFindTh",da,"post");
    setDataTh(data.list);
    $("#pageCount").html(data.number);
}
function setDataTh(data) {
    let html='';
    for (let i=0;i<data.length;i++){
        html +='   <tr>\n' +//字符串拼接
            '            <td>'+data[i].id+'</td>\n' +
            '            <td>'+data[i].name+'</td>\n' +
            '            <td><img src="'+data[i].imgHref+'" width="20px" height="20px"></td>\n' +
            '            <td><div class="biaos">'+data[i].content+'</div></td>\n' +
            '            <td><div class="biaos">'+data[i].contentcontent+'</div></td>\n' +
            '            <td>'+data[i].title+'</td>\n' +
            '            <td><input type="button" value="编辑" onclick="updatabyid('+data[i].id+')"> <a href="javascript:deletebyid('+data[i].id+')">删除</a></td>\n' +
            '        </tr>';
    }
    $("#productsFindAll").html(html);
}

